use git_tools::app;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    app::bootstrap::init().await?;
    let db = common::get_conn();
    use sea_orm::{entity::*, query::*};
    let mut result = dao::gitlab_info::Entity::find()
        .filter(dao::gitlab_info::Column::UserName.contains("姓名"))
        .paginate(&db, 10);

    // 总条数
    let page_info = result.num_items_and_pages().await?;

    tracing::info!(
        "数据总条数：{}, 页数：{}",
        page_info.number_of_items,
        page_info.number_of_pages
    );

    // 翻页查询
    while let Some(paged_rows) = result.fetch_and_next().await? {
        tracing::info!("=======当前页数：{}=======", result.cur_page());
        for ele in paged_rows {
            tracing::info!("id: {:?}, 姓名：{:?}", ele.user_id, ele.user_name);
        }
    }

    tracing::info!("查询最后页数据");
    let rows = result.fetch_page(page_info.number_of_pages - 1).await?;
    for ele in rows {
        tracing::info!("id: {:?}, 姓名：{:?}", ele.user_id, ele.user_name);
    }
    Ok(())
}
